﻿/* 11. *** Write a program that converts a number in the range [0...999] to a text corresponding to its English pronunciation. 
 * Examples: 0 --> "Zero"; 273 --> "Two hundred seventy three"; 400 --> "Four hundred"; 501 --> "Five hundred and one"; 
 *         711 --> "Seven hundred and eleven" */

// Add Reference to 'System.Numerics'.

using System;
using System.Numerics;
using System.Text;

public class PronunciationOfNumbers
{
    #region Variables
    public static BigInteger number;
    public static BigInteger divisor;
    public static int triple;
    public static int digit;
    public static StringBuilder expression = new StringBuilder();
    #endregion

    public static void Main()
    {
        do
        {
            DataInput();
            Transformation();
            Pronunciation();
            expression.Clear();
            Console.ReadKey();
        } while (true);
    }

    public static void Pronunciation()
    {
        expression[0] = char.ToUpper(expression[0]);
        Console.WriteLine("\"{0}\"", expression.ToString());
    }

    public static void Transformation()
    {
        if (number == 0)
            expression.Append("zero");
        else
        {
            if (number < 0)
            {
                expression.Append("minus");
                number *= -1;
            }

            // to one trilliard (with 21 zeros) exclusive

            divisor = 1000000000000000000;

            for (int i = 6; i > 0; i--)
            {
                triple = (int)(number / divisor);

                if (triple > 0)
                {
                    TripleDigits();

                    switch (i)
                    {
                        case 6: { expression.Append(" trillion"); break; }
                        case 5: { expression.Append(" billiard"); break; }
                        case 4: { expression.Append(" billion"); break; }
                        case 3: { expression.Append(" milliard"); break; }
                        case 2: { expression.Append(" million"); break; }
                        case 1: { expression.Append(" thousand"); break; }
                        default: break;
                    }

                    number -= (number / divisor) * divisor;
                }

                divisor /= 1000;
            }

            triple = (int)number;
            TripleDigits();
        }
    }

    public static void TripleDigits()
    {
        digit = triple / 100;

        if (digit > 0)
        {
            if (expression.Length > 0)
                expression.Append(" ");

            Say(digit);
            expression.Append(" hundred");
        }

        triple -= digit * 100;

        if ((digit > 0) || ((divisor == 1) && (expression.Length > 0) && (expression.ToString() != "minus")))
        {
            if (triple > 0)
                expression.Append(" and ");
        }
        else if (expression.Length > 0)
            expression.Append(" ");

        digit = triple / 10;
        triple -= digit * 10;

        if (digit > 0)
        {
            if ((digit == 1) || (triple == 0))
                Say(digit * 10 + triple);
            else
            {
                Say(digit * 10);
                expression.Append("-");
                Say(triple);
            }
        }
        else
            Say(triple);
    }

    public static void Say(int n)
    {
        switch (n)
        {
            case 1: { expression.Append("one"); break; }
            case 2: { expression.Append("two"); break; }
            case 3: { expression.Append("three"); break; }
            case 4: { expression.Append("four"); break; }
            case 5: { expression.Append("five"); break; }
            case 6: { expression.Append("six"); break; }
            case 7: { expression.Append("seven"); break; }
            case 8: { expression.Append("eight"); break; }
            case 9: { expression.Append("nine"); break; }
            case 10: { expression.Append("ten"); break; }
            case 11: { expression.Append("eleven"); break; }
            case 12: { expression.Append("twelve"); break; }
            case 13: { expression.Append("thirteen"); break; }
            case 14: { expression.Append("fourteen"); break; }
            case 15: { expression.Append("fifteen"); break; }
            case 16: { expression.Append("sixteen"); break; }
            case 17: { expression.Append("seventeen"); break; }
            case 18: { expression.Append("eighteen"); break; }
            case 19: { expression.Append("nineteen"); break; }
            case 20: { expression.Append("twenty"); break; }
            case 30: { expression.Append("thirty"); break; }
            case 40: { expression.Append("forty"); break; }
            case 50: { expression.Append("fifty"); break; }
            case 60: { expression.Append("sixty"); break; }
            case 70: { expression.Append("seventy"); break; }
            case 80: { expression.Append("eighty"); break; }
            case 90: { expression.Append("ninety"); break; }
            default: break;
        }
    }

    public static void DataInput()
    {
        do
        {
            Console.Clear();
            Console.Write("Enter integer number in range\n[-999 999 999 999 999 999 999; 999 999 999 999 999 999 999]\nnumber = ");
            if (BigInteger.TryParse(Console.ReadLine(), out number)
                    && (-999999999999999999 <= number / 1000) && (number / 1000 <= 999999999999999999))
                break;
        } while (true);

        Console.WriteLine("------------");
        Console.Write("{0} {1} ", number, (char)26);
    }
}